<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
class AccountController extends \App\Http\Controllers\AdminController{
    //put your code here
    public function index(Request $request) {
        $accounts = \App\Models\Account::where('status', 2);
        if ($request->has("pushstatus")) {
            $accounts->where('pushstatus', $request->input('pushstatus'));
        }
        $accounts = $accounts->paginate();
        $msg = "";
        if (!count($accounts)) {
            $msg = "没有相关内容";
        }
        $assign = compact('accounts', "msg");
        return view('admin.account.index', $assign);
    }
    
    /**
     * 修改提现申请
     * @param Request $request
     * @param type $id
     * @param type $status
     * @return type
     */
    public function edit(Request $request, $id, $status=false) {
        $account = \App\Models\Account::find($id);
        if (!$account) {
            return \Illuminate\Support\Facades\Response::json([
                'status'    => 0,
                'info'      => '商品不存在'
            ]);
        }
        if ($request->ajax() && in_array($status, array(2, 3))) {
            $account->pushtime = time();
            $account->adminmark = $request->input('adminmark');
            $account->pushstatus = $status;
            $account->save();
            return \Illuminate\Support\Facades\Response::json([
                'status'    => 1,
                'info'      => '操作成功'
            ]);
        }
        $assign = compact('account', 'status');
        return view('admin.account.edit', $assign);
    }
}
